from setuptools import setup
import os
from glob import glob

package_name = 'agv_debug_tool'

# 收集所有脚本文件，保持目录结构
def get_scripts_files():
    data_files = []
    for dirpath, dirnames, filenames in os.walk('scripts'):
        # 跳过 __pycache__ 目录
        if '__pycache__' in dirpath:
            continue
        
        # 计算目标目录路径
        # 将 'scripts/HttpServer/views' 转换为 'lib/agv_debug_tool/HttpServer/views'
        dest_dir = os.path.join('lib', package_name, os.path.relpath(dirpath, 'scripts'))
        
        # 收集当前目录中的所有文件
        files = [os.path.join(dirpath, f) for f in filenames]
        if files:
            data_files.append((dest_dir, files))
    
    return data_files

setup(
    name=package_name,
    version='0.0.1',
    packages=[package_name],
    data_files=[
        ('share/ament_index/resource_index/packages',
            ['resource/' + package_name]),
        ('share/' + package_name, ['package.xml']),
        (os.path.join('share', package_name, 'launch'), glob('launch/*')),
    ] + get_scripts_files(),  # 添加所有脚本文件，保持目录结构
    install_requires=['setuptools'],
    zip_safe=True,
    maintainer='haibo',
    maintainer_email='haibo@lgmgim.cn',
    description='Debug tool for AGV',
    license='TODO: License declaration',
    entry_points={
        'console_scripts': [
            'manage = agv_debug_tool.manage:main'
        ],
    },
)